<tagLib name="lbase"/>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>微信公众平台管理系统</title>
        <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
        <include file="Public:header" />
        <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
          <script src="__PUBLIC__/js/html5.js"></script>
        <![endif]-->
    </head>

    <!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
    <!--[if IE 7 ]> <body class="ie ie7 "> <![endif]-->
    <!--[if IE 8 ]> <body class="ie ie8 "> <![endif]-->
    <!--[if IE 9 ]> <body class="ie ie9 "> <![endif]-->
    <!--[if (gt IE 9)|!(IE)]><!--> 
    <body class="">
        <!--<![endif]-->

        <!--顶部菜单-->
        <include file="Public:navbar" />

        <!--左侧导航条-->
        <include file="Public:nav" />

        <!--右侧整体区域-->
        <div class="content">
            <div class="container-fluid">
                <div class="row-fluid">
                    <div class="row-fluid">
                        <!--右侧栏目区域start-->
                        <div class="block">
                            <a class="block-heading" data-toggle="collapse">新订阅信息添加</a>
                            <div class="block-body collapse in">

                                <div class="container-fluid" style="margin-top: 10px;">
                                    <!--右侧栏目内容区域start-->
                                    <div class="row">
                                        <div class="span12">
                                            <div class="pull-left">
                                                <a href="{:U('/'.$module_name)}" class="btn btn-primary">列 表</a>&nbsp;&nbsp;
                                                <a class="btn btn-primary" href="{$pre_url}">返 回</a>
                                            </div>
                                        </div>
                                        <!--右侧字段区域start-->
                                        <div class="span12" style="margin-top:10px;">
                                            <form class="form-horizontal" method="post">
                                                <fieldset>

                                                    <div id="legend" class="">
                                                        <legend class=""></legend>
                                                    </div>
                                                    <div class="control-group">
                                                        <!-- Select Basic -->
                                                        <label class="control-label">回复类型</label>
                                                        <div class="controls">
                                                            <select class="input-xlarge" name="msg_type">
                                                                <option value="1">单条文本</option>
                                                                <option value="2">单条图文</option>
                                                                <option value="3">图文列表</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="control-group">
                                                        <label class="control-label" for="input01">标题</label>
                                                        <div class="controls">
                                                            <input type="text" name="title" placeholder="标题" value="" class="input-xlarge">
                                                            <p class="help-block">当为单条文本时，不在用户微信显示，只对管理员有标识作用</p>
                                                        </div>
                                                    </div>

                                                    <div class="control-group">
                                                        <!-- Textarea -->
                                                        <label class="control-label">描述</label>
                                                        <div class="controls">
                                                            <div class="textarea">
                                                                <textarea name="description" style="margin: 0px; width: 478px; height: 124px;"></textarea>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="control-group">
                                                        <!-- Text input-->
                                                        <label class="control-label" for="input01">点击链接</label>
                                                        <div class="controls">
                                                            <input type="text" name="click_url" placeholder="点击的链接地址" class="input-xlarge">
                                                            <p class="help-block">完整的url链接，如为空，则自动生成文章内容页面</p>
                                                        </div>
                                                    </div>
                                                    <div class="control-group" id="pic_upload">
                                                        <label class="control-label">封面</label>

                                                        <!-- Button -->
                                                        <div class="controls">
                                                            <lbase:imgUpload name='imgupload' />
                                                            <p class="help-block">图片尺寸：640*320</p>
                                                        </div>
                                                    </div>
                                                    <div class="control-group">
                                                        <label class="control-label">状态</label>
                                                        <div class="controls">
                                                            <!-- Inline Radios -->
                                                            <label class="radio inline">
                                                                <input type="radio" value="1" name="status" checked="checked">
                                                                启用
                                                            </label>
                                                            <label class="radio inline">
                                                                <input type="radio" value="0" name="status">
                                                                禁用
                                                            </label>
                                                        </div>
                                                    </div><div class="control-group">

                                                        <!-- Textarea -->
                                                        <label class="control-label">内容</label>
                                                        <div class="controls">
                                                            <div class="textarea">
                                                                <lbase:editor name="contents" type="editor" width="70%" />
                                                                <p class="help-block">客户端显示的内容，当为单条文本时，请填写纯文本</p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="control-group">

                                                        <!-- Select Basic -->
                                                        <label class="control-label">所属图文列表主题</label>
                                                        <div class="controls">
                                                            <select class="input-xlarge" name="main">
                                                                <option value="0">顶级</option>
                                                                <foreach name="main_list" item="ml">
                                                                    <option value="{$ml.id}">{$ml.title}</option>
                                                                </foreach>
                                                            </select>
                                                        </div>

                                                    </div>

                                                    <div class="control-group">
                                                        <!-- Text input-->
                                                        <label class="control-label" for="input01">排序</label>
                                                        <div class="controls">
                                                            <input type="text" placeholder="排序" name="sort" value="0" class="input-xlarge">
                                                            <p class="help-block">图文列表的排序顺序</p>
                                                        </div>
                                                    </div>

                                                    <div class="control-group">

                                                        <!-- Textarea -->
                                                        <label class="control-label">备注</label>
                                                        <div class="controls">
                                                            <div class="textarea">
                                                                <textarea name="remark"></textarea>
                                                            </div>
                                                        </div>
                                                        <div id='pop'></div>

                                                        <div class="form-actions">
                                                            <button type="button" class="btn btn-primary" id="save">保 存</button>&nbsp;&nbsp;
                                                            <a class="btn" href="{$pre_url}">返 回</a>
                                                        </div>
                                                </fieldset>
                                            </form>
                                        </div>
                                        <!--右侧字段区域end-->
                                    </div>
                                    <!--右侧栏目内容区域end-->
                                </div>

                            </div>
                        </div>
                        <!--右侧栏目区域end-->
                    </div>
                    <footer>
                        <include file="Public:footer" />
                    </footer>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            $(function() {
                $('[name=click_url]').parent().parent().hide();
                $('#pic_upload').hide();
                $('[name=main]').parent().parent().hide();
                $('[name=sort]').parent().parent().hide();


                $('[name=msg_type]').change(function() {
                    msg_type_change()
                });

                $('[name=main]').change(function() {
                    main_change()
                });

                function main_change() {
                    var id = $('[name=main]').val();
                    if (id == '0') {
                        $('[name=sort]').parent().parent().hide();
                    } else {
                        $('[name=sort]').parent().parent().show();
                    }
                }

                function msg_type_change() {
                    var value = $('[name=msg_type]').val();

                    switch (value) {
                        case "1":
                            $('[name=click_url]').parent().parent().hide();
                            $('#pic_upload').hide();
                            $('[name=main]').parent().parent().hide();
                            $('[name=sort]').parent().parent().hide();
                            break;
                        case "2":
                            $('[name=click_url]').parent().parent().show();
                            $('#pic_upload').show();
                            $('[name=main]').parent().parent().hide();
                            $('[name=sort]').parent().parent().hide();
                            break;
                        case "3":
                            $('[name=click_url]').parent().parent().show();
                            $('#pic_upload').show();
                            $('[name=main]').parent().parent().show();
                            //                $('[name=sort]').parent().parent().hide();
                            break;
                    }
                }

                $('#save').click(function() {
                    contents_editor.sync();
                    var data = $('form').serialize();
                    $('#save').attr('disabled', 'disabled');
                    $.ajax({
                        type: "POST",
                        url: app_url + "/" + module_name + "/insert",
                        data: data,
                        dataType: 'json',
                        cache: false,
                        success: function(data) {
                            success(data);
                        },
                        error: function() {
                            error();
                        }
                    });


                });

                $('#pop').ajaxStart(function() {
                    $('#pop').html('<div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">×</button>数据请求中，请稍候...</div>')
                            .fadeIn("slow");
                });

                function success(data) {
                    if (data.data == 1) {
                        $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>信息添加成功！</div>')
                                .fadeIn("slow")
                                .fadeOut(5000);
                    } else {
                        $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>信息添加失败！</div>')
                                .fadeIn("slow")
                                .fadeOut(5000);
                    }
                }


                function error() {
                    $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>远程服务器请求失败！</div>')
                            .fadeIn("slow")
                            .fadeOut(5000);
                }
            });
        </script>
    </body>
</html>


